package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dpmain.customer.CustomerDo;
import com.qk.dto.Customer.CustomerDto;
import com.qk.dto.Customer.CustomerListDto;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @文件名: CustomerComtroller
 * @作者: DX
 * @创建日期: 2025/10/16
 * @描述:
 */
@RestController
@RequestMapping("/customers")
public class CustomerComtroller {

    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer) {
        customerService.updateById(customer);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id) {
        Customer customer = customerService.getBaseMapper().selectById(id);
        return Result.success(customer);
    }

    @PostMapping
    public Result add(@RequestBody CustomerDto dto) {
        customerService.addCustomer(dto);
        return Result.success();
    }

    @GetMapping
    public Result list(CustomerListDto dto) {

        PageResult<CustomerDo> pageResult = customerService.customerList(dto);

        return Result.success(pageResult);
    }
}
